package org.smart4j.framework.common.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;

/**
 * @author YooLin1c
 * @version 1.0.0
 * @since 2018-02-07 21:01
 */
@Slf4j
public class FileUtil {

    public static String getRealFileName(String fileName) {
        return FilenameUtils.getName(fileName);
    }

    public static File createFile(String filePath) {
        File file;
        file = new File(filePath);
        File parentDir = file.getParentFile();
        if (!parentDir.exists()) {
            try {
                FileUtils.forceMkdir(parentDir);
            } catch (IOException e) {
                log.error(String.format("create file[{}] failed!", parentDir.getPath()), e);
                throw new RuntimeException(e);
            }
        }
        return file;
    }
}
